package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC461 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int hammingDistance(int x, int y) {
            if (x < y) {
                int temp = x;
                x = y;
                y = temp;
            }

            String xStr = Integer.toBinaryString(x);
            String yStr = Integer.toBinaryString(y);

            int i = xStr.length() - 1, j = yStr.length() - 1, count = 0;
            while (j >= 0) {
                if (yStr.charAt(j--) != xStr.charAt(i--)) ++count;
            }

            while (i >= 0) if (xStr.charAt(i--) != '0') ++count;

            return count;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.hammingDistance(1, 4));
    }

    public static void main(String[] args) throws Exception {
        LC461 an = new LC461();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
